﻿using RealtorsPortal.Business_Logic_Layer;
using RealtorsPortal.Data_Access_Layer;
using RealtorsPortal.Entities;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RealtorsPortal.AdminCP
{
    public partial class AdvertisementAdDetails : System.Web.UI.Page
    {
        AdvertisementsDAL advDALObj = new AdvertisementsDAL();
        AdvertisementsDAO advObj = new AdvertisementsDAO();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["ID"] != null)
            {
                advObj.AdvId = Convert.ToInt32(Request.QueryString["ID"].ToString());
                LoadAdvertisementDetails();
            }
        }

        private void LoadAdvertisementDetails() {
            DataTable dt = new DataTable();
            dt = advDALObj.GetAdvertisementDetails(advObj);
            lblAgentName.Text = " " + dt.Rows[0]["FirstName"].ToString() +" "+ dt.Rows[0]["LastName"].ToString();
            lblPackage.Text = " " + dt.Rows[0]["PackageName"].ToString();
            lblCategory.Text = " " + dt.Rows[0]["CategoryName"].ToString();
            lblPrice.Text = " " + dt.Rows[0]["Price"].ToString();
            lblPostedDate.Text = " " + dt.Rows[0]["PostedDate"].ToString();
            lblExpDate.Text = " " + dt.Rows[0]["ExpDate"].ToString();
            lblTitle.Text = " " + dt.Rows[0]["Title"].ToString();
            lblAddress.Text = " "+dt.Rows[0]["Address"].ToString() +" " + dt.Rows[0]["DistrictName"].ToString() + " " + dt.Rows[0]["CityName"].ToString() + " " + dt.Rows[0]["RegionName"].ToString() + " " + dt.Rows[0]["CountryName"].ToString();
            lblArea.Text = " " + dt.Rows[0]["LandArea"].ToString();
            lblFloor.Text = " " + dt.Rows[0]["Floor"].ToString();
            lblBuildYear.Text = " " + dt.Rows[0]["BuiltYear"].ToString();
            lblBathroom.Text = " " + dt.Rows[0]["BathRoom"].ToString();
            lblBedroom.Text = " " + dt.Rows[0]["BedRoom"].ToString();
            lblAmenities.Text = " " + dt.Rows[0]["Amenities"].ToString();
            lblDescription.Text = " " + dt.Rows[0]["Description"].ToString();
        }

        protected void btnReturn_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/AdminCP/MyAdvertisement.aspx");
        }

        protected void btnEdit_Click(object sender, EventArgs e)
        {
            string AdvId = advObj.AdvId.ToString();
            //Response.Redirect("~/AdminCP/EditAdvertisement.aspx?ID="+AdvId);
            Server.Transfer("~/AdminCP/EditAdvertisement.aspx?ID=" + AdvId);
        }


        protected void btnDel_Click(object sender, EventArgs e)
        {
            AdsImages adsObj = new AdsImages();
            adsObj.AdvId = advObj.AdvId;
            AdsImagesDAL adsDalObj = new AdsImagesDAL();
            int resultImage = adsDalObj.DeleteAdsImages(adsObj);
            if(resultImage > 0){
                int result = advDALObj.DeleteAdvertisements(advObj);
                if (result > 0)
                {
                    Utilities.Show("The Advertise is deleted!");
                    Response.Redirect("~/AdminCP/MyAdvertisement.aspx");
                }
                else
                {
                    Utilities.Show("There is an error to delete this advertise!");
                }
            }  
        }

    }
}